<?php

$hostname="h50mysql103.secureserver.net";
$username="inklamp";
$password="AMPpr1me";
$dbname="inklamp";
$is_success="false";
$datastore=$_GET["datastore"];
$cfgId=$_GET["cfgId"];
$subjectId=$_GET["subjectId"];
$currentPrime=$_GET["currentPrime"];
$currentNeutral=$_GET["currentNeutral"];
$trialsCompleted=$_GET["trialsCompleted"];
$startTime=$_GET["startTime"];
$fixDur=$_GET["fixDur"];
$primeDur=$_GET["primeDur"];
$blankDur=$_GET["blankDur"];
$targetDur=$_GET["targetDur"];
$maskDur=$_GET["maskDur"];
$result=$_GET["result"];
$userinfo=$_GET["userinfo"];

$connection = mysql_connect($hostname, $username, $password);
mysql_select_db($dbname, $connection);

# Store new record
$sql = 'INSERT INTO '.$datastore.' (ID, cfgId, subjectId, currentPrime, currentNeutral, trialsCompleted, startTime, fixDur, primeDur, blankDur, targetDur, maskDur, result, userinfo) VALUES (NOW(), \''.$cfgId.'\', \''.$subjectId.'\', \''.$currentPrime.'\', \''.$currentNeutral.'\', \''.$trialsCompleted.'\', \''.$startTime.'\', \''.$fixDur.'\', \''.$primeDur.'\', \''.$blankDur.'\', \''.$targetDur.'\', \''.$maskDur.'\', \''.$result.'\', \''.$userinfo.'\')';
$sql_result = mysql_query($sql, $connection);

if ($sql_result)
{

} else {
	$message_to_send = 'Invalid INSERT query: '.mysql_error().' ';
   	$message_to_send .= 'Whole INSERT query: ' . $sql;
	# error_log($message_to_send, 1, "saleem@sloan.mit.edu");
}

# Check if record exists
$sql = 'SELECT * FROM '.$datastore.' WHERE subjectId LIKE \''.$subjectId.'\' AND trialsCompleted LIKE \''.$trialsCompleted.'\'';
$sql_result = mysql_query($sql, $connection);

if ($sql_result) {
	if (mysql_num_rows($sql_result))
	{
		$is_success = "true";
	} else {
		$is_success = 'No rows returned. ';
   		$is_success .= 'Whole query: ' . $sql;
		# error_log($is_success, 1, "saleem@sloan.mit.edu");
	}
} else {
	$is_success = 'Invalid SELECT query: '.mysql_error().' ';
   	$is_success .= 'Whole query: ' . $sql;
	# error_log($is_success, 1, "saleem@sloan.mit.edu");
}

echo $is_success;

mysql_close($connection);
?>